using NHibernate;
using NhibernateDemoCore;

namespace NhibernateDemoConsole
{
    internal class CreateCustomer
    {
        public void Execute(ISessionFactory factory)
        {
            using (var session = factory.OpenSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    try
                    {
                        var customer1 = new Customer
                                            {
                                                Name = "Specialty Bakers, Inc.",
                                                BillingAddress = new Address
                                                                     {
                                                                         Line1 = "450 S State Rd",
                                                                         City = "Marysville",
                                                                         State = "PA",
                                                                         Zip = "17053"
                                                                     }
                                            };

                        session.Save(customer1);
                        tx.Commit();
                    }
                    catch
                    {
                        tx.Rollback();
                        throw;
                    }
                }
            }
        }
    }
}